package com.dsbridge.enrollment.dao;

import java.util.List;

import javax.sql.DataSource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
import org.springframework.stereotype.Repository;

import com.dsbridge.enrollment.dao.mappers.CourseAuthorRowMapper;
import com.dsbridge.enrollment.model.CourseAuthorDTO;

@Repository("courseAuthorDAO")
public class CourseAuthorDAO {
	
	private SimpleJdbcTemplate simpleJdbcTemplate; 
	
	@Autowired
	private DataSource datasource;
	
	public int create(CourseAuthorDTO courseAuthor){
		simpleJdbcTemplate=new SimpleJdbcTemplate(datasource);
		
		String insertSQL="INSERT INTO Course_Authors(author,login_name,password,gender_mf,first_name,middle_name,last_name,address_line1,address_line2,city,state,zipcode)VALUES(?,?,?,?,?,?,?,?,?,?,?,?)";
        int i=simpleJdbcTemplate.update(insertSQL, courseAuthor.getAuthor(),courseAuthor.getLoginName(),
        		courseAuthor.getPassword(),courseAuthor.getGender(),courseAuthor.getFirstName(),
        		courseAuthor.getMiddleName(),courseAuthor.getLastName(),courseAuthor.getAddressLine1(),
        		courseAuthor.getAddressLine2(),courseAuthor.getCity(),courseAuthor.getState(),
        		courseAuthor.getZipcode());
		return i;
	}
	public List<CourseAuthorDTO> retriveAllAuthors(){
		 simpleJdbcTemplate=new SimpleJdbcTemplate(datasource);
		 String sql="select * from course_authors";
		 return simpleJdbcTemplate.query(sql, new CourseAuthorRowMapper());
		
	}

}
